package com.zretc.controller;

import com.github.pagehelper.PageInfo;
import com.zretc.entity.Notice;
import com.zretc.entity.ResponseResult;
import com.zretc.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * @author 周文涛
 * 公告消息api
 */
@RestController
@RequestMapping("system/public")
public class NoticeController {

    @Autowired
    private NoticeService noticeService;

    // 查询
    @GetMapping("/")
    public PageInfo<Notice> getAll(String title,
                                   String pageSize,
                                   String pageNum){
        HashMap<String, String> stringStringHashMap = new HashMap<>();
        stringStringHashMap.put("title",title);
        stringStringHashMap.put("pageSize",pageSize);
        stringStringHashMap.put("pageNum",pageNum);
        return noticeService.getAll(stringStringHashMap);
    }

    // 详情
    @GetMapping("/{id}")
    public Notice getOne(@PathVariable("id")Integer noticeId){
        return  noticeService.getOne(noticeId);
    }

    // 发布
    @PostMapping("/add")
    public ResponseResult publish(@RequestBody Notice notice){
        return noticeService.insert(notice);
    }

    // 编辑
    @PutMapping("/")
    public ResponseResult edit(@RequestBody Notice notice){
        return noticeService.update(notice);
    }

    // 删除
    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable("id")Integer noticeId){
        return  noticeService.delete(noticeId);
    }
}
